package com.chuangke.system.controller;

import com.alibaba.druid.util.StringUtils;
import com.chuangke.common.http.HttpResult;
import com.chuangke.common.idgen.IdManager;
import com.chuangke.system.dao.SysAttachmentDao;
import com.chuangke.system.entity.SysAttachment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("sysAttachment")
public class SysAttachmentController {

    @Autowired
    private SysAttachmentDao sysAttachmentDao;

    @PreAuthorize("hasAuthority('login:action')")
    @PostMapping(value = "/save")
    public HttpResult save(@RequestBody SysAttachment sysAttachment) {
        if(StringUtils.isEmpty(sysAttachment.getId())){
            sysAttachment.setId(IdManager.nextId());
        }
        sysAttachmentDao.save(sysAttachment);
        return HttpResult.ok(sysAttachment.getId());
    }

}
